define([
        'app/utils/WebUtils',
        'app/utils/WeixinUtils',

        'text!app/tpl/top2Tabs.html',
        'text!app/tpl/recommedOrgList.html',
        'text!app/tpl/myOrgList.html',

        "app/service/OrganizationService",

        "app/directive/OrganizationDirective"
        
        
        ], function (
        WebUtils,
        WeixinUtils,

        top2TabsTpl,
        recommedOrgListTpl,
        myOrgListTpl,

        OrganizationService,

        OrganizationDirective
    ) {

    

    var controller = function (userUuid) {

        //0. Weixin Disabled
        WeixinUtils.disableAll();

        //1. Data Initialized
        OrganizationService.initMyOrganizationList(userUuid,function(resp){

            if($.isNull(resp)){
                $.redirectTo($.wjtBaseBackend + "/mvc/authorize?state=login");
                return;
            }

            if(resp.status!="200"){
                $.redirectTo($.wjtBaseBackend + "/mvc/authorize?state=login");
                return;
            }
                    
            //2. Weixin Initialized
            WeixinUtils.disableAll();

            //3. tpl Initialized - Never change!!!
            var tpl = WebUtils.tplInitialized();

            //4. UI Initialized
            var top2tabsUI = _.template(top2TabsTpl)({
                "tab1_name": "我的列表",
                "tab2_name": "热门推荐"
            });

            var myOrgListUI = _.template(myOrgListTpl)({
                "myOrgList": resp.result,
                "unionid": $.getHashUrlParam("unionid")
            });


            //4. Assemble
            tpl.append(top2tabsUI)
            tpl.find(".tab1-content").append(myOrgListUI);
            tpl.find(".swiper-container").swiper({
                pagination: '.swiper-pagination',
                paginationClickable: true
            });



            //5. Render - Never change!!!
            WebUtils.render(tpl);

            //6. Directive initialized
            OrganizationDirective.directive_RecommendOrgListTab();


        })




        //7. routechange - Never change!!!
        controller.onRouteChange = WebUtils.routeChange;

    };

    return controller;


});
